package controller;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import persistence.PersistenceEvento;
import model.Evento;

@WebServlet("/ServletDeletaEvento")
public class ServletDeletaEvento extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

    public ServletDeletaEvento() {
        super();
        // TODO Auto-generated constructor stub
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		Evento evento = requestToEvento(request);
	
		PersistenceEvento.deleteEvento(evento);
		
		RequestDispatcher dispatcher = request.getRequestDispatcher("/menu.jsp");
		dispatcher.forward(request, response);
	}

	private Evento requestToEvento(HttpServletRequest request) {
		String nomeEvento = request.getParameter("evento");
		Evento evento = new Evento();
		evento.setNomeEvento(nomeEvento);
		
		return evento;
	}

}
